<?
/* if($result->type == 'paid'){
  $this->view('admin/invoices/paid_view');
  }elseif($result->type == 'box'){
  $this->view('admin/invoices/box_view');
  }elseif($result->type == 'related'){
  $this->view('admin/invoices/related_view');
  }
 */
?>

<div class="row-fluid">
    <div class="span12">
        <div class="box corner-all">
            <div class="box-header grd-white corner-top">
                <div class="header-control">
                    <a data-box="collapse"><i class="icofont-caret-up"></i></a>
                </div>
                <span><?= lang('label_menu_link_invoicies') ?></span>
            </div>
            <div class="box-body">

                <table id="datatablestools" class="table table-hover responsive">
                    <thead>
                        <tr>
                            <th style="width:38%;"><?= lang('label_items') ?></th>
                            <th style="width:11%;"><?= lang('label_product_price') ?></th>
                            <th style="width:10%;"><?= lang('label_product_quentity') ?></th>
                            <th style="width:11%;"><?= lang('label_shiping') ?></th>
                            <th style="width:10%;"><?= lang('label_discount') ?></th>
                            <th style="width:20;"><?= lang('label_total') ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if (isset($items)) { ?>
                            <?php foreach ($items as $item) { ?>
                                <tr <?php
                                foreach ($sdata as $dt) {
                                    if ($dt->item_id == $item->id && $dt->canceled == 'YES') {
                                        ?>
                                            style="background-color: #f7e4e4; text-decoration: line-through" title="<?= lang('label_wallet_rejected') ?>"
                                        <?php } elseif ($dt->item_id == $item->id && $dt->accept == 'YES') { ?>
                                            style="background-color: #e8f2e6" title="<?= lang('label_accept') ?>"
                                            <?php
                                        }
                                    }
                                    ?>>
                                    <td><?= $item->title ?></td>
                                    <td><?= $item->price ?></td>
                                    <td><?= $item->amount ?></td>
                                    <td><?= $item->shiping ?></td>
                                    <td><?= $item->discount ?></td>
                                    <td><b><?= $item->total_price ?></b> <?= lang('label_rial') ?></td>
                                </tr>
                            <?php } ?>
                        <?php } else { ?>
                        <td><?= lang($result->title) ?></td>
                        <td><?= $result->total ?></td>
                        <td>--</td>
                        <td><?= $result->shiping ?></td>
                        <td><?= $result->discount ?></td>
                        <td><b><?= $result->must_pay ?></b> <?= lang('label_rial') ?></td>
                    <?php } ?>

                    <tr>
                        <td colspan="5"><?= lang('label_sub_total') ?></td>
                        <td><b><?= $result->total ?></b> <?= lang('label_rial') ?></td>
                    </tr>
                    <tr>
                        <td colspan="5"><?= lang('label_shiping_total') ?></td>
                        <td><b><?= $result->shiping ?></b> <?= lang('label_rial') ?></td>
                    </tr>
                    <tr>
                        <td colspan="5"><?= lang('label_discount_total') ?></td>
                        <td><b><?= $result->discount ?></b> <?= lang('label_rial') ?></td>
                    </tr>
                    <tr>
                        <td colspan="5"><strong><?= lang('label_item_total') ?></strong></td>
                        <td><b><span><?= $result->must_pay ?></span> <?= lang('label_rial') ?></b></td>
                    </tr>
                    </tbody>
                </table>
            </div><!-- /box-body -->
            <div class="tool" style="margin-top: 15px">
                <?php if (in_array($result->cancel, array('USER', 'ADMIN'))) { ?>
                    <a class="btn btn-info" href="javascript:void(0)"> <?= lang('label_canceled_by_' . strtolower($result->cancel)) ?></a>
                <?php } else { ?>
                    <?
                    if ($result->confirm_status == 'NO' && $result->payment_status == 'NO') {
                        if ($result->itemes == 'YES') {
                            $itemsaccept = get_items_num_accepted($result->inv_num);
                            $totalitems = get_items_num($result->inv_num);
                            $itemsrefused = get_items_num_refuse($result->inv_num);
                            if ($itemsaccept + $itemsrefused < $totalitems) {
                                ?>
                                <a class="btn" href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/senditems/<?= $result->inv_num ?>"><i class="icon-check"></i>  <?= lang('label_send_to_seller') ?></a>
                            <? } else { ?>
                                <a class="btn" href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/confirminv/<?= $result->inv_num ?>"><i class="icon-check"></i>  <?= lang('label_confirm_inv') ?></a><? } ?>
                        <?php } else { ?>
                            <a class="btn" href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/confirminv/<?= $result->inv_num ?>"><i class="icon-check"></i>  <?= lang('label_confirm_inv') ?></a><? } ?>
                    <?php }
                    ?> 
                    <? if ($result->payment_status == 'NO') { ?><a class="btn btn-inverse" href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/cancel/<?= $result->inv_num ?>"><i class="icon-off"></i>  <?= lang('label_cancel') ?></a><? } ?>
                    <? if ($result->confirm_status == 'NO' && $result->payment_status == 'YES') { ?><a class="btn btn-inverse" href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/confirm_pay/<?= $result->inv_num ?>"><i class="icon-check"></i>  <?= lang('label_menu_link_confirm_pay') ?></a><? } ?>
                    <a class="btn" href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/edit/<?= $result->inv_num ?>"><i class="icon-edit"></i>  <?= lang('label_edit') ?></a>
                <?php } ?>
                <a  class="btn btn-danger delete_confirm " href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/delete/<?= $result->inv_num ?>"><i  class="icon-trash"></i> <?= lang('label_delete') ?></a>

                <a class="btn btn-primary" href="<?= base_url(ADMIN_FOLDER . '/invoicies') ?>"><i class="icon-backward"></i>&nbsp;&nbsp;&nbsp;<?= lang('label_back') ?></a>
            </div>
        </div><!-- /box -->
    </div><!-- /span -->
</div><!--/datatables tools-->
